package com.example.test;

import java.util.HashMap;

import net.duohuo.dhroid.activity.BaseActivity;
import net.duohuo.dhroid.adapter.recycleadapter.NetBeanRecycleAdapter;
import net.duohuo.dhroid.adapter.recycleadapter.RecyclerBaseAdapter.OnItemClickListener;
import net.duohuo.dhroid.adapter.recycleadapter.RecyclerBaseAdapter.OnItemLongClickListener;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView.LayoutManager;
import android.view.View;
import android.widget.TextView;

import com.example.test.api.API;
import com.example.test.views.RefreshRecycleViewAndMore;

public class RecyclerViewActivity extends BaseActivity {

	RefreshRecycleViewAndMore ListV;

	//
	NetBeanRecycleAdapter<HashMap<String, Object>> adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_recycleview);
		ListV = (RefreshRecycleViewAndMore) findViewById(R.id.recyclerview);
		initAdapter();
	}

	private void initAdapter() {
		LinearLayoutManager manage = new LinearLayoutManager(
				RecyclerViewActivity.this);
		manage.setOrientation(OrientationHelper.VERTICAL);
		ListV.setLayoutManager(manage);
		adapter = new NetBeanRecycleAdapter<HashMap<String, Object>>(
				new API().marketGoodList, RecyclerViewActivity.this,
				R.layout.item_list);

		TextView text = new TextView(RecyclerViewActivity.this);
		text.setText("Header1");
		adapter.addHeaderView(text);
		TextView head2 = new TextView(RecyclerViewActivity.this);
		head2.setText("Header2");
		adapter.addHeaderView(head2);
		TextView footView = new TextView(RecyclerViewActivity.this);
		footView.setText("foot");
		adapter.addFootView(footView);

		adapter.fromWhat("list");
		adapter.addparam("user_id", "7");
		adapter.addparam("communityid", "1");
		adapter.addparam("catid", "37");
		adapter.addField("title", R.id.name);
		adapter.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(View itemV, int position) {
				HashMap<String, Object> map = adapter.getTItem(position
						- adapter.getHeadersCount());

			}
		});

		adapter.setOnItemLongClickListener(new OnItemLongClickListener() {

			@Override
			public void onItemLogClick(View itemV, int position) {
				HashMap<String, Object> map = adapter.getTItem(position
						- adapter.getHeadersCount());

			}
		});

		ListV.setAdapter(adapter);

	}

}
